from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from apps.goods.models import *


# from apps.warehouse.models import *


# Register your models here.

# class GoodsSpecificationsOptionInline(admin.TabularInline):
#     model = GoodsSpecificationsOption
#     extra = 5
#     style = 'table'  # 列表显示，one：只显示一条  accordion：缩略列表显示，可下拉  tab：横向tab显示 stacked：块显示 table：列表


class GoodsSpecificationsInfoInline(admin.TabularInline):
    model = GoodsSpecificationsInfo
    extra = 5
    style = 'table'  # 列表显示，one：只显示一条  accordion：缩略列表显示，可下拉  tab：横向tab显示 stacked：块显示 table：列表


class GoodsMarketIdInline(admin.TabularInline):
    model = GoodsMarketId
    extra = 1
    style = 'table'  # 列表显示，one：只显示一条  accordion：缩略列表显示，可下拉  tab：横向tab显示 stacked：块显示 table：列表


# class GoodsBrandIdAdminInline(admin.TabularInline):
#     model = GoodsBrandId
#     extra = 1
#     style = 'table'


class GoodsCategory1Admin(ImportExportModelAdmin):
    list_display = ('name', 'date_joined')
    list_filter = ['date_joined']
    # list_editable = ['name']
    list_per_page = 10
    search_fields = ['name']


class GoodsCategory2Admin(ImportExportModelAdmin):
    list_display = ('category1', 'name', 'date_joined')
    list_filter = ['category1__name', 'date_joined']
    # list_editable = ['name']
    list_per_page = 10
    ordering = ['category1']
    search_fields = ['name']


class GoodsPcbLibAdmin(ImportExportModelAdmin):
    list_display = ('name', 'date_joined', 'desc')
    list_filter = ['date_joined']
    list_editable = ['desc']
    list_per_page = 10
    search_fields = ['name']
    ordering = ['name']


class GoodsAdmin(ImportExportModelAdmin):
    list_display = (
        'my_id', 'show_image', 'name', 'pcb', 'stock', 'date_joined', 'desc')
    list_filter = ['category2__category1__name', 'category2__name', 'pcb__name', 'date_joined']
    list_display_links = ['show_image']
    list_per_page = 20
    search_fields = ['my_id', 'name']
    # radio_fields = {"brand": admin.HORIZONTAL,
    #                 "category2": admin.HORIZONTAL,
    #                 "pcb": admin.HORIZONTAL, }
    inlines = [GoodsMarketIdInline,GoodsSpecificationsInfoInline]


class GoodsSpecificationsAdmin(ImportExportModelAdmin):
    list_display = ('name', 'date_joined')
    list_filter = ['date_joined']
    list_per_page = 10


class GoodsSpecificationsOptionAdmin(ImportExportModelAdmin):
    list_display = ('value', 'date_joined')
    list_filter = ['value']
    search_fields = ['spec__name', 'value']
    ordering = ['value']
    list_per_page = 10


class GoodsSpecificationsInfoAdmin(ImportExportModelAdmin):
    list_display = ('get_category2', 'goods', 'spec', 'option')
    list_filter = ['goods__category2__name', 'goods', 'spec', 'option__value']
    search_fields = ['goods__my_id']
    list_per_page = 20


class GoodsMarketAdmin(ImportExportModelAdmin):
    list_display = ('name', 'show_image', 'telephone', 'address', 'date_joined', 'desc')
    list_filter = ['date_joined']
    list_display_links = ['show_image']
    list_per_page = 10
    search_fields = ['name']


class GoodsBrandAdmin(ImportExportModelAdmin):
    list_display = ('name', 'show_image', 'date_joined', 'desc')
    list_filter = ['date_joined']
    list_display_links = ['show_image']
    list_editable = ['desc']
    list_per_page = 10
    search_fields = ['name']


# 商城编号
class GoodsMarketIdAdmin(ImportExportModelAdmin):
    list_display = ('goods', 'get_goods_image', 'market_num', 'show_market_image')
    list_display_links = ['get_goods_image']
    list_filter = ['market__name']
    ordering = ['goods']
    list_per_page = 20
    search_fields = ['goods__my_id', 'market_num']


# # 品牌型号
# class GoodsBrandIdAdmin(ImportExportModelAdmin):
#     list_display = ('get_goods_image', 'goods', 'brand_num', 'show_brand_image', 'date_joined')
#     list_display_links = ['get_goods_image']
#     list_filter = ['brand__name']
#     ordering = ['goods']
#     list_per_page = 20
#     search_fields = ['goods__my_id', 'brand_num']


# 修改网页title和站点header。
admin.site.site_title = "电子工艺后台管理"
admin.site.site_header = "电子工艺后台管理"

admin.site.register(GoodsCategory1, GoodsCategory1Admin)
admin.site.register(GoodsCategory2, GoodsCategory2Admin)
admin.site.register(GoodsBrand, GoodsBrandAdmin)
admin.site.register(GoodsPcbLib, GoodsPcbLibAdmin)
admin.site.register(Goods, GoodsAdmin)
admin.site.register(GoodsSpecifications, GoodsSpecificationsAdmin)
admin.site.register(GoodsSpecificationsOption, GoodsSpecificationsOptionAdmin)
admin.site.register(GoodsSpecificationsInfo, GoodsSpecificationsInfoAdmin)
admin.site.register(GoodsMarket, GoodsMarketAdmin)
admin.site.register(GoodsMarketId, GoodsMarketIdAdmin)
# admin.site.register(GoodsBrandId, GoodsBrandIdAdmin)
